package org.example.domain.enums;


import lombok.Getter;
import org.example.domain.po.MessagePO;
import org.example.domain.po.PingMessagePO;
import org.example.domain.po.PongMessagePO;
import org.example.domain.po.RpcRequestMessagePO;
import org.example.domain.po.RpcResponseMessagePO;

/**
 * @description: 消息类型枚举
 * @author: feixiang.li
 * @date: 2025-01-02 20:25
 */
@Getter
public enum MessageTypeEnum {

    PING(1, PingMessagePO.class),

    PONG(2, PongMessagePO.class),

    RPC_REQUEST(3, RpcRequestMessagePO.class),

    RPC_RESPONSE(4, RpcResponseMessagePO.class),
    ;

    private final int value;

    private final Class<? extends MessagePO> clazz;

    public Class<? extends MessagePO> getMessageClass() {
        return clazz;
    }

    public Integer getValue() {
        return value;
    }

    MessageTypeEnum(int messageType, Class<? extends MessagePO> messageClass) {
        this.value = messageType;
        this.clazz = messageClass;
    }

    public static Class<? extends MessagePO> getMessageClassByType(int messageType) {
        for (MessageTypeEnum messageTypeEnum : MessageTypeEnum.values()) {
            if (messageTypeEnum.getValue() == messageType) {
                return messageTypeEnum.getMessageClass();
            }
        }
        return null;
    }

    public static MessageTypeEnum getMessageTypeEnumByType(int messageType) {
        for (MessageTypeEnum messageTypeEnum : MessageTypeEnum.values()) {
            if (messageTypeEnum.getValue() == messageType) {
                return messageTypeEnum;
            }
        }
        return null;
    }
}
